package com.learn.acm.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.*;

/**
 * @author zhongshitao
 * @date 2020/10/27 2:33 下午
 */
@Slf4j
@RestController
public class TestController {



    @ResponseBody
    @RequestMapping("file")
    public String getBigFile() {
        String fileStr = null;
        try {
            fileStr = readFile("file.json");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        log.info("--->{}", fileStr.length());
        return fileStr;
    }

    private String readFile(String fileName) throws FileNotFoundException {
        File file = ResourceUtils.getFile("classpath:" + fileName);
        BufferedReader br = new BufferedReader(new FileReader(file));
        String s="";
        StringBuilder configContentStr = new StringBuilder();
        try {
            while((s = br.readLine()) != null) {
                configContentStr.append(s);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return configContentStr.toString();
    }
}
